10. Exercise: Refactor the VideoDao
L9 17 VideoDao Refactored FIX
Now it’s your turn to complete this exercise yourself.
This is a simple one!
1. Refactor to use LiveData:
In Room.kt, all you have to do is update getVideos() to return a LiveData of a List of DatabaseVideo.
If you want to start at this step, you can download this exercise code from: Step.03-Exercise-Refactor-VideoDao.
You will find plenty of //TODO comments to help you complete this exercise, and if you get stuck, go back and watch the video again.
Once you’re done, you can check your solution against the solution we’ve provided here Step.03-Solution-Refactor-VideoDao or using this git diff
Task Description:
Check the steps below as you implement them to complete this exercise.
Task Feedback:
Wasn’t it easy? Great!
VideoDao
SOLUTION:
- You want to watch for changes to the database and update the UI dynamically.
- You want to be able to call the query from the UI thread.
- You want Room to run the query to run on a background thread.